<?php

use App\Jobs\TestJob;
use App\Models\News;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;
use Laravel\Octane\Facades\Octane;
use PhpAmqpLib\Connection\AMQPStreamConnection;

Route::get('/s', function () {
    $server = app('octane.swoole.server');
    dd($server);
});

Route::get('/debug', function () {
    return Octane::table('websocket_connections')->toArray();
});

Route::get('/octane-check', function () {
    return 'Octane Works: '. config('octane.server');
});

Route::get('/job', function () {

    Log::channel('base')->info('=====发送消息=====');
    TestJob::dispatch(['name' => 'test']);
    return '任务发布成功';
});

Route::get('/test', function () {
   dd(config('queue'));
});

Route::any('/callback', function (Request $request) {
    Log::channel('base')->info('=====接收消息====='.date('Y-m-d H:i:s'));
    Log::channel('base')->info(json_encode($request->all()));
    return 'success';
});


Route::get('/mq', function () {

    $connection = new AMQPStreamConnection(
        'localhost',  // 主机名或IP地址
        5672,         // 端口号，默认是5672
        'guest',  // 用户名
        'guest',  // 密码
        '/',          // vhost，默认是'/'
    );

    $channel = $connection->channel();

    echo "Connected to RabbitMQ\n";
    $channel->close();
    $connection->close();
    return 'RabbitMQ连接成功';
});



Route::get('/news', function () {
   $news =  News::search('world')->options([
       'query_by' => 'name, content'
   ]) ->get();
    dd($news->toArray());
});

Route::get('/c-n', function () {
    $new =  News::query()->create([
        'name' => '测试'.date('Y-m-d H:i:s'),
        'content' => '测试内容'.date('Y-m-d H:i:s'),
        'created_at' => now(),
        'updated_at' => now(),
    ]);
    $new->searchable();
    dd($new);
});


Route::post('/news', function (Request $request) {
    $new =  News::query()->create([
        'name' => $request->input('name'),
        'content' =>  $request->input('content'),
    ]);
    dd($new);
});


// http://47.99.53.207:15672/#/

